package service

import (
	"context"
	"strconv"
	"video-srv/basic/config"
	__ "video-srv/basic/proto/rpc"
	"video-srv/handler/model"
)

type VideoServer struct {
	__.UnimplementedVideoServer
}

func (s *VideoServer) GetVideoList(_ context.Context, in *__.GetVideoListReq) (*__.GetVideoListResp, error) {
	var video model.Video
	list, err := video.GetVideoList(config.DB)
	if err != nil {
		return nil, err
	}
	return &__.GetVideoListResp{
		List: list,
	}, nil
}
func (s *VideoServer) GetHistory(_ context.Context, in *__.GetHistoryReq) (*__.GetHistoryResp, error) {
	var his model.HisTory
	list, err := his.GetHistory(config.DB)
	if err != nil {
		return nil, err
	}
	return &__.GetHistoryResp{
		List: list,
	}, nil
}
func (s *VideoServer) FindHis(_ context.Context, in *__.FindHisReq) (*__.FindHisResp, error) {
	var order model.Order
	err := order.FindOrder(config.DB)
	if err != nil {
		return nil, err
	}
	return &__.FindHisResp{
		OrderSn:          order.OrderSn,
		MemberExpireTime: strconv.Itoa(order.MemberExpireTime),
	}, nil
}
